package com.wn.pettyloan.controller;

import com.wn.pettyloan.util.OssUtil;
import com.wn.pettyloan.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: pettyloan
 * @ClassName UpDownloadController
 * @description: 上传下载图片文件控制层
 * @author: 韩旭
 * @create: 2022-12-07 14:34
 **/

@RestController
public class UpDownloadController {

    @Autowired
    private OssUtil ossUtil;//引入工具类

    @PostMapping("/uploadoss")
    public Result fileUpload(@RequestParam("file") MultipartFile file) {
        try {
            String url = ossUtil.uploadFile(file); //调用OSS工具类
            return Result.ok(url);
        } catch (Exception e) {
            return Result.error("上传失败");
        }
    }
}